using System;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.SqlClient;
using Be.Timvw.Framework.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Data
{
    [TestClass]
    public class WhenGettingDbConnectionFromDbProviderFactoryHelper
    {
        [TestMethod]
        public void ShouldReturnSqlConnectionWithSqlClientConnectionStringName()
        {
            using(new ConfigurationFileSession("DbProviderFactoryHelper.config"))
            {
                using(DbConnection dbConnection = DbProviderFactoryHelper.GetDbConnection("SqlClientConnectionStringName"))
                {
                    Type actual = dbConnection.GetType();

                    Type expected = typeof(SqlConnection);

                    Assert.AreEqual(expected, actual);
                }
            }
        }

        [TestMethod]
        public void ShouldReturnOdbcConnectionWithOdbcConnectionStringName()
        {
            using(new ConfigurationFileSession("DbProviderFactoryHelper.config"))
            {
                using(DbConnection dbConnection = DbProviderFactoryHelper.GetDbConnection("OdbcConnectionStringName"))
                {
                    Type actual = dbConnection.GetType();

                    Type expected = typeof(OdbcConnection);

                    Assert.AreEqual(expected, actual);
                }
            }
        }
    }
}